package com.future.controller;

import com.future.common.annotation.ControllerMapping;
import com.future.common.annotation.JsonBody;
import com.future.common.annotation.NoNeedLogin;
import com.future.common.base.BaseController;
import com.future.common.utils.IDUtil;
import com.future.dao.XjrwDao;
import com.future.dao.XjyDao;
import com.future.model.Xjrw;
import com.future.requestbean.XjrwAddBean;
import com.future.requestbean.XjrwEditBean;
import com.jfinal.aop.Inject;

/**
 * 巡检任务
 * @author ThinkPad
 *
 */
@ControllerMapping("/xjrw")
public class XjrwController extends BaseController{
	@Inject
	private XjyDao xjyDao;
	
	@Inject
	private XjrwDao xjrwDao;
	
	public void queryXjrw(String xjrwmc, String xjdw, String xjfw, String sfwc){
		renderResult("xjrwlist", this.xjrwDao.queryXjrw(xjrwmc, xjdw, xjfw, sfwc));
	}
	
	@NoNeedLogin
	public void wxaqueryXjrw(String xjryid){
		renderResult("xjrwlist", this.xjrwDao.queryXjrwByXjryid(xjryid));
	}
	
	public void addXjrw(@JsonBody XjrwAddBean xjreaAddBean){
		String xjryid = xjreaAddBean.getXjryid();
		String xjryname = this.xjyDao.findById(xjryid).getName();
		
		Xjrw xjrw = beanToModel(xjreaAddBean,Xjrw.class);
		xjrw.setRwid(IDUtil.getId());
		xjrw.setXjryname(xjryname);
		xjrw.save();
		renderSuccess();
	}
	
	public void deleteXjrw(String rwid){
		this.xjrwDao.deleteById(rwid);
		renderSuccess();
	}
	
	public void editXjrw(@JsonBody XjrwEditBean xjrEditBean){
		String xjryid = xjrEditBean.getXjryid();
		String xjryname = this.xjyDao.findById(xjryid).getName();
		Xjrw xjrw = beanToModel(xjrEditBean,Xjrw.class);
		xjrw.setXjryname(xjryname);
		xjrw.update();
		renderSuccess();
	}
	
	public void completeXjrw(String xjrwid){
		this.xjrwDao.findById(xjrwid).setSfwc("1").update();
		renderSuccess();
	}
}
